package org.kazuhiko.rpg.display.menu;

import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glColor4f;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glTexCoord2f;
import static org.lwjgl.opengl.GL11.glVertex2f;

import org.kazuhiko.rpg.core.Game;
import org.kazuhiko.rpg.core.menu.MenuItem;
import org.kazuhiko.rpg.core.types.TextureType;
import org.kazuhiko.rpg.manager.TextureManager;
import org.newdawn.slick.opengl.Texture;

public class MenuButton extends MenuItem
{	
	public MenuButton( float x, float y, float width, float height )
	{
		super( x, y, width, height );
	}
	
	/*
	public MenuButton( float x, float y, float width, float height, String text, int fontSize, Color fontColor )
	{
		super( x, y, width, height, text, fontSize, fontColor );
	}
	
	public MenuButton( float x, float y, float width, float height, String text, int fontSize, Color fontColor, float r, float g, float b, float a )
	{
		super( x, y, width, height, text, fontSize, fontColor, r, g, b, a );
	}
	*/
	
	public MenuButton( float x, float y, float width, float height, TextureType textureType, float r, float g, float b, float a )
	{
		super( x, y, width, height, textureType, r, g, b, a );
	}

	@Override
	public void render()
	{
		Texture textureButton = TextureManager.getManager().getTexture( getTextureType() );
		if( textureButton != null )
		{
			textureButton.bind();
		}
		
		glBegin( GL_QUADS );
		{
			if( textureButton != null )
			{	
				glColor4f( 1f, 1f, 1f, 1f );
			}
			else
			{
				glColor4f( getR(), getG(), getB(), getA() );
			}
			
			if( textureButton != null )
			{
				glTexCoord2f( 0f, 0f );
			}
			glVertex2f( getX(), getY() );
			
			if( textureButton != null )
			{
				glTexCoord2f( 0f, textureButton.getHeight() );
			}
			glVertex2f( getX(), getY() + getHeight() );
			
			if( textureButton != null )
			{
				glTexCoord2f( textureButton.getWidth(), textureButton.getHeight() );
			}
			glVertex2f(  getX() + getWidth(), getY() + getHeight() );
			
			if( textureButton != null )
			{
				glTexCoord2f( textureButton.getWidth(), 0 );
			}
			glVertex2f(  getX() + getWidth(), getY() );
		}
		glEnd();
	}

	@Override
	public void onClick()
	{
		Game.getGame().cleanUp( false );
	}
	
}
